package com.onlineMIS.ORM.DAO.headQ.barCodeGentor;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.base.BaseOrder;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.HeadQTag;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.HeadQTagGroup;

@Repository
public class HeadQTagGroupDaoImpl extends BaseDAO<HeadQTagGroup> {

	/**
	 * 根据客户标签权重，获取排序后的HeadQTagGroup
	 */
	public List<HeadQTagGroup> getOrderByWithSort() {		
		DetachedCriteria criteria = DetachedCriteria.forClass(HeadQTagGroup.class);
		criteria.add(Restrictions.eq("entityType",HeadQTag.TAG_HEADQ));
		criteria.addOrder(Order.desc("sort"));
		List<HeadQTagGroup> tags = getByCritera(criteria, true);
		return tags;
		
	}
	



	/**
	 * 根据权重，获取权重分组集合
	 * @param sort
	 * @return
	 */
	public List<Integer> selectTagsBySort(Double sort) {
		List<Integer> list = new ArrayList<Integer>();
		DetachedCriteria criteria = DetachedCriteria.forClass(HeadQTagGroup.class);
		criteria.add(Restrictions.eq("entityType",HeadQTag.TAG_HEADQ));
		criteria.add(Restrictions.eq("sort",sort));
		List<HeadQTagGroup> tags = getByCritera(criteria, true);
		if (tags != null) {
			for (HeadQTagGroup headQTagGroup : tags) {
				list.add(headQTagGroup.getId());
			}
		}
		return list;
	}

	
	/**
	 * 获取供应商分组的id
	 * @return
	 */
	public List<Integer> selectSupplierGroupIds() {
		List<Integer> list = new ArrayList<Integer>();
		DetachedCriteria criteria = DetachedCriteria.forClass(HeadQTagGroup.class);
		criteria.add(Restrictions.eq("entityType",HeadQTag.TAG_SUPPLIER));		
		List<HeadQTagGroup> tags = getByCritera(criteria, true);
		if (tags != null) {
			for (HeadQTagGroup headQTagGroup : tags) {
				list.add(headQTagGroup.getId());
			}
		}
		return list;
	}




	/**
	 * 获取客户分组的id
	 * @return
	 */
	public List<Integer> selectCustGroupIds() {
		List<Integer> list = new ArrayList<Integer>();
		DetachedCriteria criteria = DetachedCriteria.forClass(HeadQTagGroup.class);
		criteria.add(Restrictions.eq("entityType",HeadQTag.TAG_HEADQ));		
		List<HeadQTagGroup> tags = getByCritera(criteria, true);
		if (tags != null) {
			for (HeadQTagGroup headQTagGroup : tags) {
				list.add(headQTagGroup.getId());
			}
		}
		return list;
	}



	public List<Integer> selectByGroup(Integer group) {
		List<Integer> list = new ArrayList<Integer>();
		DetachedCriteria criteria = DetachedCriteria.forClass(HeadQTagGroup.class);
		criteria.add(Restrictions.eq("entityType",group));		
		List<HeadQTagGroup> tags = getByCritera(criteria, true);
		if (tags != null) {
			for (HeadQTagGroup headQTagGroup : tags) {
				list.add(headQTagGroup.getId());
			}
		}
		return list;
	}



}
